/**
 * 
 */
package web;

import static org.mentawai.core.ApplicationManager.getRealPath;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import org.mentawai.core.ActionConfig;
import org.mentawai.core.Forward;
import org.mentawai.filter.FileUploadFilter;
import org.mentawai.filter.IoCFilter;
import org.mentawai.ioc.Component;
import org.mentawai.ioc.DefaultComponent;

import sistema.contexto.AvaliacaoBLFacade;
import web.actions.LinguagemManager;
import web.actions.ProblemaManager;
import web.actions.SubmeterSolucao;
import web.actions.ZerarSistema;
import facade.Facade;

/**
 * @author Thiago Emmanuel Pereira da Cunha Silva, thiago.manel@gmail.com
 * @author João Arthur Brunet Monteiro, joaoarthurbm_at_gmail.com
 * @since 03/04/2006
 */
public class ApplicationManager extends org.mentawai.core.ApplicationManager {
	 

	public void loadActions() {
//		fazendo com que a facade esteja no escopo da aplicacao.
		Component facade = new DefaultComponent(Facade.class);
		addGlobalFilter(new IoCFilter(facade, "facade", APPLICATION));
		
		List argsPath = new LinkedList();
		argsPath.add(getRealPath()+File.separator+"problemas");
		Component problemsPath = new DefaultComponent(String.class);
		addGlobalFilter(new IoCFilter(problemsPath, "problemsPath", APPLICATION));
		
		
		List args = new LinkedList();
		args.add(getRealPath()+File.separator+"data");
		
		Component avalFacade = new DefaultComponent(AvaliacaoBLFacade.class, args);
		addGlobalFilter(new IoCFilter(avalFacade, "avalFacade", APPLICATION));
		
		ActionConfig acAddLing = new ActionConfig("LinguagemManager", LinguagemManager.class, "addLinguagem");
		acAddLing.addConsequence(SUCCESS, new Forward("/adicaoConcluida.jsp"));
		acAddLing.addConsequence(ERROR, new Forward("/error.jsp"));
		addActionConfig(acAddLing);
		
		ActionConfig listaLing = new ActionConfig("LinguagemManager", LinguagemManager.class, "listaLinguagem");
		listaLing.addConsequence(LinguagemManager.SUCCESS, new Forward("/listaLinguagem.jsp"));
		listaLing.addConsequence(LinguagemManager.ERROR,  new Forward("/error.jsp"));
		addActionConfig(listaLing);
		
		
		ActionConfig acAddProb = new ActionConfig("ProblemaManager", ProblemaManager.class, "addProblema");
		acAddProb.addConsequence(ProblemaManager.SUCCESS, new Forward("/index.jsp"));
		acAddProb.addConsequence(ProblemaManager.ERROR,  new Forward("/error.jsp"));
		acAddProb.addFilter(new FileUploadFilter());
		addActionConfig(acAddProb);
		
		ActionConfig listaProb = new ActionConfig("ProblemaManager", ProblemaManager.class, "listaProblema");
		listaProb.addConsequence(ProblemaManager.SUCCESS, new Forward("/listaProblema.jsp"));
		listaProb.addConsequence(ProblemaManager.ERROR,  new Forward("/error.jsp"));
		addActionConfig(listaProb);
		
		ActionConfig submeter = new ActionConfig("submeterSolucao", SubmeterSolucao.class);
		submeter.addConsequence(SubmeterSolucao.SUCCESS, new Forward("/resultado.jsp"));
		submeter.addConsequence(SubmeterSolucao.ERROR,  new Forward("/error.jsp"));
		submeter.addFilter(new FileUploadFilter());
		addActionConfig(submeter);
		
		ActionConfig zerar = new ActionConfig("zerarSistema", ZerarSistema.class);
		zerar.addConsequence(ProblemaManager.SUCCESS, new Forward("/index.jsp"));
		addActionConfig(zerar);
//		
//		ActionConfig acAdiciona = new ActionConfig("Adiciona", CadastraUsuarios.class);
//		acAdiciona.addConsequence(CadastraUsuarios.SUCCESS, new Redirect("/adicaoConcluida.jsp"));
//		acAdiciona.addConsequence(CadastraUsuarios.ERROR,  new Forward("/error.jsp"));
//		addActionConfig(acAdiciona);
//		acAdiciona.addFilter(new FileUploadFilter());
//		
//		ActionConfig acUpload = new ActionConfig("/Upload", UploadFileAction.class);
//		acUpload.addConsequence(UploadFileAction.SUCCESS, new Forward("/welcome.jsp"));
//		acUpload.addConsequence(UploadFileAction.ERROR, new Forward("/erro.jsp"));
//        addActionConfig(acUpload);
//        
//        acUpload.addFilter(new FileUploadFilter());
			
	}
	
}

